﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './my.scss'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
    	userinfo:Taro.getStorageSync('userinfo'),  
    	ewminfo:'',
		bginfo:''
    }
  }
  config = {
    navigationBarTitleText: '邀请好友'
  }
  componentWillMount () {
  	
	  this.getbg();
  	this.getewm();
  }
  
  onShareAppMessage(res){
  	var byfrom=this.$router.params.byfrom;
  	var dealerId=Taro.getStorageSync('dealerId');
  	var shopId=Taro.getStorageSync('shopId')
  	if(byfrom=='mybill'){
    	var title = '线下聚合支付码'
    	var path = '/pages/mybill/mybill?scene='+dealerId+'mybill'+shopId+'&shopId='+shopId
    }
  	else{
  		var webinfo=Taro.getStorageSync('webinfo')
			if(webinfo){
				const accountInfo = Taro.getAccountInfoSync();
				const appid=accountInfo.miniProgram.appId;
				var shareid=this.$router.params.shareid
	  		var title = '就差你了，一起来玩'
	  		var path = '/pages/login/login?scene='+shareid+'shareid&appId='+appid
	  		
			}
			else{
				var dateinfo=Taro.getStorageSync('dateinfo');
	  		var title = '一物一格一码一世界，一起玩转物格码世界'
	  		var path = '/pages/xijia/grouplist?scene='+dateinfo.userid+'introducer'
	  		
	    }
  	}
  	console.log(path)
    let imageUrl = ''
    return CommonJs.onShareAppMessage(title, path, imageUrl)
  }
  componentDidShow () {
  	
  }
  getbg(){
	var dealerId=Taro.getStorageSync('dealerId')
	if(!dealerId){
		dealerId=-1
	}
	var url='/advert/papi/v1.9/apply-setting/byType/1/'+dealerId
	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
			if(res.data&&res.data.length>0&&res.data[0].logo){
				_this.setState({
				  bginfo:res.data[0].logo
				})
			}
		    else{
				_this.setState({
				  bginfo:'https://minichat.g2ma.com/kedouimg/ewmbg.jpg'
				})
			}
					 
  	})
  }
  getewm(){
  	var byfrom=this.$router.params.byfrom;
  	if(byfrom=='mybill'){
  		//聚合支付码
  		Taro.setNavigationBarTitle({title:'线下聚合支付码'})
  		var _this=this
  		var dealerId=Taro.getStorageSync('dealerId');
  		var shopId=Taro.getStorageSync('shopId')
  		var url='/user/getWxSmallQrCode?page=pages/mybill/mybill&scene='+dealerId+'mybill'+shopId+'&shopId='+shopId
			CommonJs.ajaxRequest(url,'','GET',function(res){
				_this.setState({
				  ewminfo:res.content
				})
			})
  	}
  	else{
			var webinfo=Taro.getStorageSync('webinfo')
			if(webinfo){
				const accountInfo = Taro.getAccountInfoSync();
				const appid=accountInfo.miniProgram.appId;
				var shareid=this.$router.params.shareid
				var url='/user/getAppIdWxSmallQrCode?page=pages/login/login&scene='+shareid+'shareid&appId='+appid
			}
			else{
				var url='/user/getUserQRCode'
			}
			var _this=this
			CommonJs.ajaxRequest(url,'','GET',function(res){
					_this.setState({
				  ewminfo:res.content
				})
			})
		}
  }
  render () {
   	const userinfo=this.state.userinfo
   	const ewminfo=this.state.ewminfo
    return (
    	
      <View className='page ewm-page'>
    		<View className='ewm-box'>
       			<View className='tx' style="background-color:#fff"><Image className="img" mode="scaleToFill" src={this.state.bginfo}></Image></View>
        		<View className='userewm'>
        			<View className='ewmimg'>
        				<Image className="img" mode="widthFix" src={ewminfo.wxQrCode}></Image>
        			</View>
       			</View>
       		</View>
      </View>
    )
  }
}

 